package controller;

import java.util.Random;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class Login implements org.springframework.web.servlet.mvc.Controller {

	@RequestMapping("login_test")
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

		if (request.getParameter("name").equals("1181819395@qq.com")
				&& request.getParameter("password").equals("blog20131123")) {
			HttpSession session = request.getSession();
			session.setAttribute("login", new Random().nextLong() + "");
			Cookie coo = new Cookie("login", session.getAttribute("login") + "");
			response.addCookie(coo);
			return new ModelAndView("redirect:console/console");
		} else {
			return new ModelAndView("redirect:login");
		}
	}

	@RequestMapping(path="login")
	public String loginJsp() {
		return "login";
	}

}
